// $Id: from_str_w.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/uuid.hpp>
#include <xpcom/string.hpp>

#ifdef XPCOM_HAS_2BYTE_WCHAR_T

BOOST_AUTO_TEST_CASE(test_from_str_w)
{
    using namespace xpcom;

    // Parse success
    uuid id1 = { 0x64D47515, 0xADE3, 0x45d1,
            { 0xAB, 0xAE, 0x3A, 0x93, 0x62, 0xC5, 0xA5, 0x51 } };
    uuid id2;

    const wstring id_str1 = L"{64D47515-ADE3-45d1-ABAE-3A9362C5A551}XYZ";
    const wstring id_str2 = L"64D47515-ADE3-45d1-abae-3A9362C5A551";
    const wstring id_str3 = L"{64D47515-ADE3-45d1-ABAE-3A62C5A551}";
    const wstring id_str4 = L"64D47515-ADE3-45d1-ABAE-3A62C5A551";
    const wstring id_str5 = L"{64D47515-ADE3-45d1-ABAE-3A9362C5A551XYZ";
    const wstring id_str6;
    const wstring id_str7 = L"64D470515-ADE3-45d1-abae-3a9362c5a551XYZ";
    const wstring id_str8 = L"64D47S15-ADE3-45d1-abae-3a9362c5a551XYZ";

    id2.from_str(id_str1);
    BOOST_CHECK(id1 == id2);

    id2.from_str(id_str2);
    BOOST_CHECK(id1 == id2);

    try {
        id2.from_str(id_str3);
        BOOST_CHECK(false);
    } catch (std::exception&) {
        BOOST_CHECK(true);
    } catch (...) {
        BOOST_CHECK(false);
    }

    try {
        id2.from_str(id_str4);
        BOOST_CHECK(false);
    } catch (std::exception&) {
        BOOST_CHECK(true);
    } catch (...) {
        BOOST_CHECK(false);
    }

    try {
        id2.from_str(id_str5);
        BOOST_CHECK(false);
    } catch (std::exception&) {
        BOOST_CHECK(true);
    } catch (...) {
        BOOST_CHECK(false);
    }

    try {
        id2.from_str(id_str6);
        BOOST_CHECK(false);
    } catch (std::exception&) {
        BOOST_CHECK(true);
    } catch (...) {
        BOOST_CHECK(false);
    }

    try {
        id2.from_str(id_str7);
        BOOST_CHECK(false);
    } catch (std::exception&) {
        BOOST_CHECK(true);
    } catch (...) {
        BOOST_CHECK(false);
    }

    // TODO Bad hex digit
    id2.from_str(id_str8);
    BOOST_CHECK(id1 != id2);
#if 0
    try {
        id2.from_str(id_str8);
        BOOST_CHECK(false);
    } catch (std::exception&) {
        BOOST_CHECK(true);
    } catch (...) {
        BOOST_CHECK(false);
    }
#endif
}

#endif
